/**
 * Writed by yura and mak
 */

package wz.legend;

import java.io.IOException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpException;
import org.apache.http.HttpMessage;
import org.apache.http.HttpResponse;
import org.apache.http.HttpResponseFactory;
import org.apache.http.impl.entity.EntityDeserializer;
import org.apache.http.impl.entity.LaxContentLengthStrategy;
import org.apache.http.impl.io.HttpResponseParser;
import org.apache.http.io.SessionInputBuffer;
import org.apache.http.message.LineParser;
import org.apache.http.params.HttpParams;

public class ResponseParser extends HttpResponseParser {

    private EntityDeserializer entitydeserializer;
    private SessionInputBuffer buffer;

    public ResponseParser(SessionInputBuffer buffer, LineParser parser,
            HttpResponseFactory responseFactory, HttpParams params) {
        super(buffer, parser, responseFactory, params);
        this.buffer = buffer;
        this.entitydeserializer = createEntityDeserializer();
        
    }

    protected EntityDeserializer createEntityDeserializer() {
        return new EntityDeserializer(new LaxContentLengthStrategy());
    }

    @Override
    public HttpMessage parse() throws IOException, HttpException {
        HttpResponse response = (HttpResponse) super.parse();
        HttpEntity entity = this.entitydeserializer.deserialize(buffer, response);
        response.setEntity(entity);
        return response;
    }
    
    

}
